var cards = document.querySelector('.cards');
var images = document.querySelectorAll('.card__img');
var backgrounds = document.querySelectorAll('.card__bg');
var range = 40;
var calcValue = function calcValue(a, b) {
  return ((a / b) * range - range / 2).toFixed(1);
};

var timeout = void 0;
document.addEventListener(
  'mousemove',
  function (_ref) {
    var x = _ref.x,
      y = _ref.y;
    if (timeout) {
      window.cancelAnimationFrame(timeout);
    }

    timeout = window.requestAnimationFrame(function () {
      var yValue = calcValue(y, window.innerHeight);
      var xValue = calcValue(x, window.innerWidth);
      cards.style.transform =
        'rotateX(' + yValue + 'deg) rotateY(' + xValue + 'deg)';
      [].forEach.call(images, function (image) {
        image.style.transform =
          'translateX(' + -xValue + 'px) translateY(' + yValue + 'px)';
      });
      [].forEach.call(backgrounds, function (background) {
        background.style.backgroundPosition =
          xValue * 0.45 + 'px ' + -yValue * 0.45 + 'px';
      });
    });
  },
  false
);

var goPhotosPage = document.getElementsByClassName('card__one')[0];
goPhotosPage.addEventListener('click', function () {
  window.location.href = './html/photos.html';
});

var goPhotosPage = document.getElementsByClassName('card__two')[0];
goPhotosPage.addEventListener('click', function () {
  window.location.href = './projects/articles/dist/index.html';
});
